<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/easyui/_viewJS.jsp" %>
<!DOCTYPE>
<html>
<head>
	<title>吐槽11</title>
	<script src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>
	<script src="${basePath}resources/js/wechat/js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
	<span style="margin-left: 10px">吐槽</span>
</header>
<!-- header end -->

<div class="page tc_page">
	<div class="tc_inner">
		<ul>
			<form id="myForm" name="myForm">

				<li>
					<div>
						<ul>
							<c:if test="${!empty deviceLists}">
								<select id="adminid" name="adminid"></select>
							</c:if>

						</ul>
					</div>
				</li>
				<li><input type="text" id="commettitle" name="commettitle" class="errorTitle" placeholder="故障标题"></li>
				<li><textarea id="commetcontent" name="commetcontent" id="" maxlength="200" cols="30" rows="10"
							  placeholder="故障内容（限200字以内）"></textarea></li>
			</form>
			<li>
				<p>添加图片</p>

				<div class='append_img'>
					<a class='append_imgadd' style="width:0;border:none; overflow:hidden;"><img src="" alt=""></a>
					<a id="GC_tucao_img"
					   href="JavaScript:void(0);">+</a>
				</div>
			</li>
		</ul>
		<div class="tc_postbutton cur"><a id="GC_tucao_submit" href="JavaScript:;">提交</a></div>
	</div>
</div>
<!-- footer -->
<div class="newfooter">
	<c:if test="${financeMachine==1}">
		<a href="${basePath}wechat/income/accounts/mainView" class="newfooter1">账目</a>
	</c:if>
	<c:if test="${machine==1}">
		<a href="${basePath}wechat/operate/device/listView" class="newfooter2">设备</a>
		<a href="${basePath}wechat/operate/place/listView" class="newfooter3">场地</a>
	</c:if>
	<a href="${basePath}wechat/commet/showView" class="newfooter4 cur">吐槽</a>
	<a class="newfooter5" href="javascript:;">我的</a>
</div>
<!-- footer end -->

<!-- top加号弹窗 -->
<%@include file="/WEB-INF/jsp/wechat/_top.jsp" %>
<!-- top加号弹窗 end -->
<script type="application/javascript">
	//点击异步加载
	$(document).delegate(".select_value ul li", "click", function () {
		$(".select_value em").text($(this).text());
		$('#adminid').val($(this).attr("id"));
	});

	wx.config({
		debug: false,
		appId: '${jsret.appid}',
		timestamp: '${jsret.timestamp}',
		nonceStr: '${jsret.nonceStr}',
		signature: '${jsret.signature}',
		jsApiList: ['chooseImage', 'uploadImage']
	});

	wx.ready(function(){
		var localid = "";
		$("#GC_tucao_img").click(function () {
			wx.chooseImage({
				count: 1, // 默认9
				sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				success: function (res) {
					var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
					localid = localIds[0];
					$(".append_imgadd").find("img").attr("src", localid).end().css({
						"width": "3rem",
						"border": "1px solid #CCC"
					});
				}
			});
		});

		$("#GC_tucao_submit").click(function () {

			var commettitle = $('#commettitle').val();
			if (typeof(commettitle) == "undefined" || commettitle.length == 0) {
				alert("吐槽标题不能为空!");
				return;
			}
			var commetcontent = $('#commetcontent').val();
			if (typeof(commetcontent) == "undefined" || commetcontent.length == 0) {
				alert("吐槽内容不能为空!");
				return;
			}

			if (typeof(localid) == "undefined" || localid.length <= 0) {
				alert("请选择图片！");
			} else {
				wx.uploadImage({
					localId: localid, // 需要上传的图片的本地ID，由chooseImage接口获得
					isShowProgressTips: 1, // 默认为1，显示进度提示
					success: function (res) {
						var serverId = res.serverId; // 返回图片的服务器端ID
						//当上传微信服务器成功后，跳转到后台服务器
						if (typeof(serverId) == "undefined" || serverId.length <= 0) {
							alert("请重新上传图片！");
						} else {
							$.ajax({
								url: '${basePath}wechat/commet/add',
								type: 'POST',
								data: {
									'commettitle': $('#commettitle').val(),
									'commetcontent': $('#commetcontent').val(),
									'adminid': $('#adminid').val(),
									"mediaid": serverId
								},
								error: function (response) {
									ViewHelper.func.ajaxWechatErrorMessage(response);
								},
								success: function (ret) {
									alert(ret.info);
								}
							});
						}
					}
				});
			}
		});
	});
</script>
</body>
</html>
<%@ include file="/resources/js/wechat/_wechatui.jsp" %>
<script type="application/javascript">
	//限制故障标题输入框长度、类型
	$(".errorTitle").long({
		"element": ".errorTitle",
		"action": "keyup",
		"stringl": "1",
		"stringls": "30",
		"reg": /^.{0,35}$/,
		"stavalue": "故障情况"
	});
</script>
